package chapter.second.item2;

//构建器模式
public class Product {
	private final int size;
	private final int calories;
	private final int fat;
	private final int sodium;
	
	public static class Builder{
		//必要参数
		private final int size;
		private final int calories;
		//可选参数
		private int fat = 0;
		private int sodium = 0;
		
		public Builder(int size,int calories){
			this.size = size;
			this.calories = calories;
		}
		
		public Builder fat(int val){
			fat = val;
			return this;
		}
		
		public Builder sodium(int val){
			sodium = val;
			return this;
		}
		
		public Product build(){
			return new Product(this);
		}
		
	}
	
	private Product(Builder builder){
		size = builder.size;
		calories = builder.calories;
		fat = builder.fat;
		sodium = builder.sodium;
	}
	
	public static void main(String[] args) {
		Product p = new Product.Builder(1, 2).fat(0).sodium(5).build();
	}
	
}
